home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7217 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: dispatch.news.demon.net!demon!barwick.demon.co.uk
  2. From: paul@barwick.demon.co.uk (Paul Stockton)
  3. Newsgroups: comp.lang.c++
  4. Subject: Visual C++ Scrollbar problem (Please HELP)
  5. Date: Thu, 22 Feb 1996 08:52:19 GMT
  6. Message-ID: <312c2e9d.285610@news.demon.co.uk>
  7. NNTP-Posting-Host: barwick.demon.co.uk
  8. X-NNTP-Posting-Host: barwick.demon.co.uk
  9. X-Newsreader: Forte Agent .99d/16.182
  10.  
  11. Does anybody know why a horizontal scroll bar I have in my application
  12. continuously sends WM_HSCROLL messages AFTER I have let go of the
  13. mouse button.  If I move the mouse off the scroll bar, the messages
  14. stop, but restart again as soon as I place the mouse back onto the
  15. scroll bar (that is without pressing the mouse button again!).
  16.  
  17. I am convinced it is due to the fact that in my OnHScroll message
  18. handler I am performing quite a lengthy operation on receipt of a
  19. SB_LINELEFT or SB_LINERIGHT scroll bar code.  I know this, because if
  20. I comment out the 'lengthy' code, it works fine.
  21.  
  22. Because the message handler is being called whilst I am doing this
  23. 'lengthy operation' my application soon reports a stack overflow, so I
  24. included a flag to check as soon as the message handler is called and
  25. to return if it was set.  This cured my stack overflow problem, but
  26. I'm no further forward in the multiple scroll message problem.
  27.  
  28. Basically my question is, how do I get the scroll bar to send just one
  29. message when I click the scroll bar arrows or, if that is not
  30. possible, how do I perform a lengthy operation on receipt of a
  31. WM_HSCROLL message without the scroll bar sending tons of messages?
  32.  
  33. Here's my OnHScroll message handler:
  34.  
  35.  
  36. void HitView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
  37. pScrollBar)
  38. {
  39. static BOOL Scrolling = FALSE;        // scrolling flag 
  40.  
  41.     if(Scrolling) return;        // if busy, return immediately
  42.     Scrolling = TRUE;        // set to TRUE when 'lengthy
  43. op' in progress
  44.  
  45.     if (pScrollBar != NULL && pScrollBar->GetDlgCtrlID() ==
  46. IDC_HITSCROLL)
  47.     {
  48.         switch(nSBCode)
  49.         {
  50.             case SB_LINERIGHT:
  51.  
  52.                     // lengthy operation
  53.                     break;
  54.  
  55.             case SB_LINELEFT:    
  56.  
  57.                     // another lengthy operation
  58.                     break;
  59.         }
  60.     }
  61.  
  62.     CFrameWnd::OnHScroll(nSBCode, nPos, pScrollBar);
  63.  
  64.     Scrolling = FALSE;        // reset Scrolling flag
  65. }
  66.  
  67.  
  68. I would be grateful for any help.
  69.  
  70. Steve Bentley
  71. Email:  steve@barwick.demon.co.uk
  72.